home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Sound / PreludeAMP / src / args.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-16  |  4.0 KB  |  158 lines

  1. /* this file is a part of amp software, (C) tomislav uzelac 1996,1997
  2. */
  3. /* args.c  created by Andrew Richards  <A.Richards@phys.canterbury.ac.nz>
  4. */
  5.  
  6. #include "amp.h"
  7. #include "audio.h"
  8.  
  9. #ifdef __BEOS__
  10. #define __STDC__               1
  11. #include <getopt.h>
  12. #else
  13. #include "getopt.h"
  14. #endif
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18.  
  19.  
  20. void
  21. displayDisclaimer()
  22. {
  23.     /* print a warm, friendly message
  24.      */
  25.     msg("\namp %d.%d.%d, (C) Tomislav Uzelac 1996,1997\n",MAJOR,MINOR,PATCH);
  26.     msg("THIS PROGRAM COMES WITH ABSOLUTELY NO WARRANTY\n");
  27.     msg("PLEASE READ THE DOCUMENTATION FOR DETAILS\n\n");
  28. }
  29.  
  30. void
  31. displayUsage()
  32. {
  33.     int idx;
  34.  
  35.     /* Losts of printfs for stupid compilers that can't handle literal newlines */
  36.     /* in strings */
  37.  
  38.     printf("\
  39. usage: amp [options] [ MPEG audio streams... ]\n\
  40.        amp -convert [ MPEG-audio stream ] [ output file ]\n\n\
  41.   -h, -help           display this usage information and exit\n\
  42.   -v, -version        display the version information and exit\n\
  43.   -c, -convert        convert the MPEG audio stream to output file format\n\
  44.   -p, -play           play the specified MPEG audio streams (default action)\n\
  45.   -q, -quiet          supress printing of messages to STDERR\n\
  46.   -b, -buffer <size>  set the audio buffer size to <size> k\n\
  47.   -d, -dump           dump binary data to STDERR\n\
  48.   -s, -frame          show a frame counter\n\
  49.   -t, -time           show time\n\
  50.   -g, -gui            output messages to stdout instead of stderr\n\
  51.                       (for use with xmpeg3 or similar GUIs)\n\
  52.   -w                  wav output\n\
  53.       -downmix        downmix stereo streams to one channel\n\
  54.       -nobuffer       do not use an audio buffer\n\
  55.       -volume <vol>   set the volume to <vol> (0-100)\n\
  56.       -debug <opts..> When compiled in debug <opt, opt2,...> code sections\n\
  57.                       Options: ");
  58.  
  59.     for(idx=0;debugLookup[idx].name!=0;idx++)
  60.         printf("%s,",debugLookup[idx].name);
  61.     printf("\010 \n");
  62.  
  63.     exit(0);
  64. }
  65.  
  66. void
  67. displayVersion()
  68. {
  69.     printf("amp - %d.%d.%d\n",MAJOR,MINOR,PATCH);
  70.     exit(0);
  71. }
  72.  
  73.  
  74.  
  75. int
  76. argVal(char *name, char *num, int min, int max)
  77. {
  78.     int val;
  79.     
  80.     val=atoi(num);
  81.     if ((val<min) || (val>max))
  82.         die("%s parameter %d - out of range (%d-%d)\n",name,val,min,max);
  83.     return(val);
  84. }
  85.  
  86.  
  87. int
  88. args(int argc,char **argv)
  89. {
  90.     int c;
  91.  
  92.     static int showusage=0, showversion=0;
  93.  
  94.     AUDIO_BUFFER_SIZE=300*1024;
  95.     A_DUMP_BINARY=FALSE;
  96.     A_QUIET=FALSE;
  97.     A_FORMAT_WAVE=FALSE;
  98.     A_SHOW_CNT=FALSE;
  99.     A_SET_VOLUME=-1;
  100.     A_SHOW_TIME=0;
  101.     A_AUDIO_PLAY=TRUE;
  102.     A_WRITE_TO_FILE=FALSE;
  103.     A_MSG_STDOUT=FALSE;
  104.     A_DOWNMIX=FALSE;
  105.  
  106.     while (1) {
  107.         static struct option long_options[] =    {
  108.             {"help", no_argument, 0, 'h'},
  109.             {"debug", required_argument, 0, 1},
  110.             {"version", no_argument, 0, 'v'},
  111.             {"quiet", no_argument, 0, 'q'},
  112.             {"play", no_argument, 0, 'p'},
  113.             {"convert", no_argument, 0, 'c'},
  114.             {"volume", required_argument, 0, 2},
  115.             {"time", no_argument, 0, 't'},
  116.             {"frame", no_argument, 0, 's'},
  117.             {"gui", no_argument, 0, 'g'},
  118.             {"buffer", required_argument, 0, 'b'},
  119.             {"nobuffer", no_argument, &AUDIO_BUFFER_SIZE, 0},
  120.             {"dump", required_argument, 0, 'd'},
  121.             {"downmix",no_argument,0,'x'},
  122.             {0, 0, 0, 0}
  123.         };
  124.  
  125.         c = getopt_long_only(argc, argv, "xqgstwdpcb:vh", long_options,0);
  126.  
  127.         if (c == -1) break;
  128.         switch (c) {
  129.         case    1 : debugSetup(optarg); break;
  130.         case    2 : A_SET_VOLUME=argVal("Volume",optarg,0,100); break;
  131.         case 'q': A_QUIET=TRUE; break;
  132.         case 's': A_SHOW_CNT=TRUE; break;
  133.         case 't': A_SHOW_TIME=TRUE; break;
  134.         case 'w': A_FORMAT_WAVE=TRUE; break;
  135.         case 'd': A_DUMP_BINARY=TRUE; break;
  136.         case 'g': A_MSG_STDOUT=TRUE; break;
  137.         case 'p': A_AUDIO_PLAY=TRUE;A_WRITE_TO_FILE=FALSE;break;
  138.         case 'c': A_AUDIO_PLAY=FALSE;A_WRITE_TO_FILE=TRUE;break;
  139.         case 'b': 
  140. #if !defined(LINUX_REALTIME)
  141.               AUDIO_BUFFER_SIZE=1024*argVal("Buffer size",optarg,64,10000);
  142. #endif
  143.               break;
  144.         case 'v': showversion=1; break;
  145.         case 'h': showusage=1; break;
  146.         case 'x': A_DOWNMIX=TRUE;break;
  147.         case '?': exit(1);
  148.         case ':': printf("Missing parameter for option -%c\n",c); break;
  149.         }
  150.     }
  151.     if (showversion) displayVersion();
  152.     if (showusage) displayUsage();
  153.     displayDisclaimer();
  154.  
  155.     return(optind);
  156. }
  157.  
  158.